﻿@model ConferenceFunctionModel
@{
	ViewBag.Title = Resources.ConferenceFunction + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.FunctionName：<input class="easyui-textbox" id="SelFunctionName" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a class="easyui-linkbutton" iconcls="icon-search" onclick="searchData()">@Resources.Search </a>
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

<form id="frmDetail" method="post">
	@Html.AntiForgeryToken()
	<input type="hidden" id="hidConferenceId" name="ConferenceId" />
	<input type="hidden" id="hidID" name="Id" />
	<input type="hidden" id="hidStatus" name="Status" />
	<input type="hidden" id="hdnIds" name="AllId" />
</form>

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceFunction");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#SelFunctionName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceFunctionController.GetData),
					nameof(ConferenceFunctionController).GetControllerName())",
			method: "get",
			checkOnSelect: false,
			selectOnCheck: false,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(ViewBag.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceFunction, RoleType.修改))
				{
					<text>
					{
						field: "operate", align: "center", width: 100, checkbox: true,
					},
					</text>
				}
				{ field: "functionName", title: "@Resources.FunctionName", align: "center", sortable: true, width: 150 },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
					formatter: function(value, rec) {
						if (value== "@ConstValues.Status.正常") {
							return "@Resources.Normal"
						} else {
							return "@Resources.Pause"
						}
					}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100},
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 150 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
				param.conferenceId = $("#hidConferenceId").val();
			},
			onLoadSuccess: function(data) {
				for (var index=0; index<data.rows.length; index++) {
					if (data.rows[index].status == "@ConstValues.Status.正常"){
						$("#dataGrid").datagrid("checkRow",index);
					}
				}
			},
			onCheck: function (rowIndex, rowData) {
				if(rowData.status == "@ConstValues.Status.暂停"){
					editData(rowData.id, rowData.status);
				}
			},
			onUncheck: function (rowIndex, rowData) {
				if (rowData.status == "@ConstValues.Status.正常") {
					if (rowData.id == "@ConstValues.FunctionId.ConferenceAttendenceInfo" ||
						rowData.id == "@ConstValues.FunctionId.ConferenceContributeInfo") {
							var confirmMessage = "@Resources.CfmCancelCheck";
							$.messager.confirm("@Resources.Cancel", confirmMessage, function (r) {
								if (r) {
									editData(rowData.id, rowData.status);
								}
								else {
									$("input[type='checkbox']").eq(rowIndex + 1).prop("checked", true);
								}
							});
					} else {
						editData(rowData.id, rowData.status);
					}
				}
			},
			onCheckAll: function (rows) {
				var confirmMessage = "@Resources.CfmCancelCheck";
				$.messager.confirm("@Resources.Cancel", confirmMessage, function (r) {
					if (r) {
						checkAllData();
					} else {
						$("input[type='checkbox']").eq(0).prop("checked", false);
						var data = $("#dataGrid").datagrid("getData");
						for (var index=0; index<data.rows.length; index++) {
							if (data.rows[index].status == "@ConstValues.Status.正常") {
								$("#dataGrid").datagrid("checkRow", index);
							} else {
								$("#dataGrid").datagrid("uncheckRow", index);
							}
						}
					}
				});
			},
			onUncheckAll: function (rows) {
				var confirmMessage = "@Resources.CfmCancelCheck";
				$.messager.confirm("@Resources.Cancel", confirmMessage, function (r) {
					if (r) {
						unCheckAllData();
					} else {
						$("input[type='checkbox']").eq(0).prop("checked", true);
						var data = $("#dataGrid").datagrid("getData");
						for (var index=0; index<data.rows.length; index++) {
							if (data.rows[index].status == "@ConstValues.Status.正常") {
								$("#dataGrid").datagrid("checkRow", index);
							} else {
								$("#dataGrid").datagrid("uncheckRow", index);
							}
						}
					}
				});
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelFunctionName: $("#SelFunctionName").textbox("getValue")
		});
	}

	function editData(id, status) {
		if (status == "@ConstValues.Status.正常") {
			status = "@ConstValues.Status.暂停";
		} else {
			status = "@ConstValues.Status.正常";
		}
		$("#hidID").val(id);
		$("#hidStatus").val(status);
		$.post("@Url.Action(nameof(ConferenceFunctionController.Modify),
				nameof(ConferenceFunctionController).GetControllerName())",
			$("#frmDetail").serialize(),
			function(data, textStatus, jqXHR) {
				location.reload();
			}
		);
	};

	function checkAllData() {
		var status = "@ConstValues.Status.正常";
		$("#hidStatus").val(status);
		var loading = layer.load(0, {
			shade: [0.4, "#fff"]
		});
		$.post("@Url.Action(nameof(ConferenceFunctionController.ModifyAll),
				nameof(ConferenceFunctionController).GetControllerName())",
			$("#frmDetail").serialize(),
			function(data, textStatus, jqXHR) {
				location.reload();
			}
		);
	};

	function unCheckAllData() {
		var status = "@ConstValues.Status.暂停";
		$("#hidStatus").val(status);
		var loading = layer.load(0, {
			shade: [0.4, "#fff"]
		});
		$.post("@Url.Action(nameof(ConferenceFunctionController.ModifyAll),
				nameof(ConferenceFunctionController).GetControllerName())",
			$("#frmDetail").serialize(),
			function(data, textStatus, jqXHR) {
				location.reload();
			}
		);
	};
</script>
}